package org.iweb.html.api;

import java.io.Serializable;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.iweb.html.impl.basic.Form;
import org.iweb.html.impl.js.JavascriptEngineFactory;
import org.iweb.html.impl.js.engine.JavascriptEngine;

public abstract class Listener implements Serializable{

	/**
	 *
	 */
	private static final long serialVersionUID = 7908252107882763776L;
	private String id;
	private JavascriptEngine jsEngine;
	//private boolean alreadyWriteResponse=false;
	/*
	public Listener() {
		this(null);
	}
	*/

	public Listener(String id) {
		if(id==null){
			this.id=UUID.randomUUID().toString();
		}else{
			this.id=id;
		}

		//MainManager.getAppSession().getObserver().registerListener(this);

	}

	public Listener(){
		this(null);
	}

	public String getId() {
		return id;
	}

	public JavascriptEngine getJsEngine() {
		if(jsEngine==null)
			jsEngine=JavascriptEngineFactory.getInstance().getEngine();
		return jsEngine;
	}

	public abstract void run(HttpServletRequest request,Form.CustomFormBean formBean);

//	public boolean isAlreadyWriteResponse() {
//		return alreadyWriteResponse;
//	}
//
//	public void setAlreadyWriteResponse(boolean alreadyWriteResponse) {
//		this.alreadyWriteResponse = alreadyWriteResponse;
//	}

}
